var layModules = {};

$(function () {
    var Utils = {
        showToast: function (msg) {
            layModules.layer.open({
                title: '提示',
                content: msg
            });
        }
    };

    layui.use(['layer'], function () {
        layModules.layer = layui.layer;
    });

    function createUserGroup(data) {
        $.post('/front/group/_create', data, function (res) {
            if (res.code === 0) {
                Utils.showToast('创建成功');
                setTimeout(function () {
                    window.location.href = '/user/user-group.html';
                }, 1000);
            } else {
                Utils.showToast(res.msg)
            }
        }, 'json');
    }

    $('#create-form').submit(function (e) {
        e.preventDefault();
        var name = this.name.value;
        var description = this.description.value;
        var postData = {
            name: name,
            description: description
        };
        createUserGroup(postData);
        return false;
    });
});